package com.ymatou.topicrecbizer.testcase;

import java.util.Date;

import org.json.JSONObject;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.topicrecbizer.parameter.ProductListBean;
import com.ymatou.topicrecbizer.service.ProductListCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.tag.P1;

public class Ts_ProductList {
	private static ProductListBean productlistBean;
	private static ProductListCall productlistCall;
	
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("商品Topic详情列表接口");
	}

	@Before
	public void caseUp() {
		productlistBean = new ProductListBean();
		productlistCall = new ProductListCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(productlistCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ProductList_001() {
		Logger.start(true,"商品Topic详情列表接口-检查接口返回公共信息 ");
		try {
			//设置参数
			String requestid="111111";
			long timenow = new Date().getTime();
			String score = "tpscore";
			String topicId = "3377";
			
			productlistBean.setQuery("term(topicId,"+topicId+")");
			productlistBean.setInfo("userid:11,cookieid:22,idfa:33,imei:44,yid:3333,timenow:"+timenow+"");
			productlistBean.setSort("desc("+score+")");
			productlistBean.setAppkey("1");
			productlistBean.setRequestid(requestid);
			productlistBean.setModule("homepage_topic_product_list");
			productlistBean.setPlatform("appbuyer");
			productlistBean.setLimit("0,10");
			
			productlistCall.setData(productlistBean);
			productlistCall.callService();
			
			Logger.verifyEquals("OK",productlistCall.getCommonInfo("status") , "检查接口状态值");
			Logger.verifyNotNull(productlistCall.getCommonInfo("took"), "took不为空");
			Logger.verifyEquals(false, productlistCall.getCommonInfoBoo("downgrade"), "验证downgrade返回false");
			Logger.verifyEquals(false, productlistCall.getCommonInfoBoo("timeout"), "验证timeout返回flase");
			Logger.verifyEquals(requestid, productlistCall.getCommonInfo("requestid"), "验证requestid值是否为所传值");
			Logger.verifyNotNull(productlistCall.getCommonInfo("hostip"), "验证是否有返回服务器ip");
			Logger.verifyEquals(score, productlistCall.getCommonInfo("algorithm"), "验证返回排序方式是否与所传值相同");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ProductList_002() {
		Logger.start(true,"商品Topic详情列表接口-检查接口每条数据的返回值是否齐全，并且有有效值 ");
		try {
			//设置参数
			String requestid="111111";
			long timenow = new Date().getTime();
			String score = "tpscore";
			String topicId = "3377";
			
			productlistBean.setQuery("term(topicId,"+topicId+")");
			productlistBean.setInfo("userid:11,cookieid:22,idfa:33,imei:44,yid:3333,timenow:"+timenow+"");
			productlistBean.setSort("desc("+score+")");
			productlistBean.setAppkey("1");
			productlistBean.setRequestid(requestid);
			productlistBean.setModule("homepage_topic_product_list");
			productlistBean.setPlatform("appbuyer");
			productlistBean.setLimit("0,10");
			
			productlistCall.setData(productlistBean);
			productlistCall.callService();
			
			Logger.verifyEquals("OK", productlistCall.getStatus(), "验证接口返回状态是否正常");
			
			JSONObject searchInfo = (JSONObject) productlistCall.getSearchInfo();
			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
}
